package com.subsequent.controller;


import com.subsequent.dto.ScheduleBatchAddDTO;
import com.subsequent.pojo.ScheduleRules;
import com.subsequent.service.SchedulesService;
import com.subsequent.vo.ScheduleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/schedules")
public class ScheduleController {

    @Autowired
    private SchedulesService scheduleService;

    @GetMapping("/list")
    public List<ScheduleVO> list(
            @RequestParam(required = false) String doctorName,
            @RequestParam(required = false) Integer deptId,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime
    ) {
        return scheduleService.querySchedules(doctorName, deptId, status, startTime, endTime);
    }

    @GetMapping("/list2")
    public List<ScheduleVO> list(
            @RequestParam(required = false) Integer doctorId,
            @RequestParam(required = false) Integer deptId,
            @RequestParam(required = false) String status,
            @RequestParam(required = false) Integer serviceId,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startTime,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endTime
    ) {
        return scheduleService.querySchedules2(doctorId, deptId, status, serviceId, startTime, endTime);
    }
    @PostMapping("/batchAdd")
    public String batchAddSchedules(@RequestBody ScheduleBatchAddDTO dto) {
        boolean result = scheduleService.batchAddSchedules(dto);
        return result ? "success" : "fail";
    }
}